<template>
    <div class="recommendList">
        <!-- 商品列表展示 -->
        <div v-for="item in itemList" :key="item.id" class="listItem">
            <!-- 左图右文布局 -->
            <div class="itemContainer">
                <div class="left">
                    <img :src="item.imageUrl" :key="item.id" alt="商品图片" class="itemImage" />
                </div>
                <div class="right">
                    <h2 class="itemTitle">{{ item.name }}</h2>
                    <p class="shortDesc">{{ item.shortDesc }}</p>
                    <p class="longDesc">{{ item.longDesc }}</p>
                    <p class="itemPrice">价格：{{ item.price ? item.price + '¥' : '免费' }}</p>
                </div>
            </div>
            <!-- 详情按钮 -->
            <router-link :to="`/recommendDetail/${item.id}`" class="detailBtn">
                查看详情</router-link>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, reactive } from 'vue'
import axios from 'axios'

// 商品列表数据
const itemList = ref([])

const url = 'http://localhost:3000/TokyoSpots'

axios.get(url)
    .then(response => {
        console.log(response.data)
        itemList.value = response.data
    })
    .catch(error => {
        console.error(error)
    })

</script>

<style lang="css" scoped>
.recommendList {
    display: flex;
    flex-direction: column;
    gap: 30px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    margin-bottom: 100px;
}

.listItem {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.listItem:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.itemContainer {
    display: flex;
    gap: 20px;
}

.left {
    flex: 1;
    max-width: 300px;
}

.itemImage {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
}

.right {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.itemTitle {
    font-size: 22px;
    color: #333;
    margin: 0;
}

.shortDesc {
    font-size: 16px;
    color: #666;
    margin: 0;
}

.longDesc {
    font-size: 14px;
    color: #888;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.itemPrice {
    font-size: 18px;
    color: #ff6b81;
    font-weight: bold;
    margin: 10px 0 0 0;
}

.detailBtn {
    align-self: flex-end;
    padding: 8px 20px;
    background-color: #ff6b81;
    color: white;
    border: none;
    border-radius: 20px;
    text-decoration: none;
    font-size: 14px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.detailBtn:hover {
    background-color: #ff4757;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .itemContainer {
        flex-direction: column;
    }

    .left {
        max-width: 100%;
    }

    .itemImage {
        height: 180px;
    }
}

@media (max-width: 480px) {
    .recommendList {
        padding: 10px;
    }

    .listItem {
        padding: 15px;
    }

    .itemTitle {
        font-size: 18px;
    }

    .shortDesc,
    .longDesc {
        font-size: 13px;
    }

    .itemPrice {
        font-size: 16px;
    }
}
</style>